package com.dc.refactoring._5_简化函数调用._8_ReplaceParameterWithMethods;

/**
 * Description: 优化后的结果
 * @author: gdc
 * @date: 2020/12/9
 * @version 1.0
 */
public class Demo2 {

    /**
     * 数量
     */
    private double quantity;
    /**
     * 单价
     */
    private double price;

    /**
     * 获取最终价格
     */
    public double getPrice(){
        if (getDiscountLevel() == 2) {
            return getBasePrice() * 0.5;
        }
        return getBasePrice() * 0.8;
    }

    /**
     * 获取折扣钱价格
     */
    private double getBasePrice() {
        return quantity * price;
    }

    /**
     * 获取折扣等级
     */
    private int getDiscountLevel() {
        int discountLevel;
        if (quantity > 100) {
            discountLevel = 2;
        } else {
            discountLevel = 1;
        }
        return discountLevel;
    }

}
